package project.controllers.workers;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

import org.apache.log4j.Logger;

import project.model.IMaster;

public class WorkerWithMaster {
	private static final Logger log = Logger.getLogger(WorkerWithMaster.class);
	private static final String MASTER = "Master ";
	private static final String PERFORMS = " performs order #";
	private static final String BUSY = " busy";
	private static final String FREE = " free";

	static void getOrdersByMaster(IMaster master) {
		System.out.println(MASTER + master.getNameMaster() + PERFORMS
				+ master.getOrder().getNumberOrder());
	}

	static void SortMaster(ArrayList<IMaster> masterList, Comparator sortBy) {
		try {
			Collections.sort(masterList, sortBy);
			for (IMaster master : masterList) {
				if (master.getEmploymentMaster()) {
					System.out.println(MASTER + master.getNameMaster() + BUSY);
				} else {
					System.out.println(MASTER + master.getNameMaster() + FREE);
				}
			}
		} catch (NullPointerException n) {
			log.warn("Collection is empty");

		}
	}

	static void addMaster(ArrayList<IMaster> masterList, IMaster master) {
		try {
			masterList.add(master);
		} catch (NullPointerException n) {
			log.warn("Collection is empty");

		}
	}

	static void deleteMaster(ArrayList<IMaster> masterList, IMaster master) {
		try {
			ArrayList<IMaster> temp = new ArrayList<IMaster>();
			for (IMaster mas : masterList) {
				if (!mas.equals(master)) {
					temp.add(mas);
				}
			}
			masterList.clear();
			masterList.addAll(temp);
		} catch (NullPointerException n) {
			log.warn("Collection is empty");

		}
	}
}
